package org.test.client.ui.content.forms;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

import org.test.client.ui.ContentMain;
import org.test.client.ui.component.MyBasePanel;
import org.test.client.ui.component.btn.MyUIButton;
import org.test.client.ui.component.combox.MyCombox;
import org.test.client.ui.component.combox.MyComboxModel;
import org.test.client.ui.component.field.HighLightTextField;
import org.test.client.ui.component.field.TxtFieldSE;
import org.test.client.ui.component.panel.RoundPanel;
import org.test.client.ui.util.CompFactory;
import org.test.client.ui.util.VFlowLayout;

public class FormsDemo extends MyBasePanel {

	public static final String PK = "FormsDemo";
	
	public static MyCombox myCombox2 = null;
	
	public FormsDemo() {
//		this.setBackground(Color.green);
//		this.add(new JLabel(PK));
		doInit();
	}
	
	public FormsDemo(ContentMain contentMain) {
		super(contentMain);
//		this.setBackground(Color.green);
//		this.add(new JLabel(PK));
	}

	@Override
	public MyBasePanel doInit() {
		
		RoundPanel roundPanel = new RoundPanel("测试表单");
		
		roundPanel.setLayout(new VFlowLayout());
		
		//fa-group
		HighLightTextField username = HighLightTextField.createNormalField();
		TxtFieldSE icon = TxtFieldSE.createStartIcon("fa-user");
		username.start = icon;
		username.setPreferredSize(new Dimension(0,46));
		username.placeHolder = "UserName";
		
		HighLightTextField password = HighLightTextField.createNormalField();
		TxtFieldSE icon2 = TxtFieldSE.createStartIcon("fa-lock");
		password.start = icon2;
		password.setPreferredSize(new Dimension(0,46));
		password.placeHolder = "PassWord";
		
		JRadioButton web = new JRadioButton("Web client");
		JRadioButton java = new JRadioButton("Java client");
		JPanel radioPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		ButtonGroup g = new ButtonGroup();
		g.add(web);
		g.add(java);
		radioPanel.add(web);
		radioPanel.add(java);
		
		JPanel checkPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		JCheckBox checkBox = new JCheckBox("Remember me");
		checkPanel.add(checkBox);
		
		JPanel btnPanel = new JPanel();
		MyUIButton login = CompFactory.createBlueBtn(null, "Login", null);
		login.needFoucsBorder = true;
		login.setPreferredSize(new Dimension(232,36));
		MyUIButton regist = CompFactory.createBlueBtn(null, "Regist", null);
		regist.needFoucsBorder = true;
		regist.setPreferredSize(new Dimension(232,36));
		btnPanel.add(login);
		btnPanel.add(regist);
		
		JPanel checkBoxPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		MyCombox myCombox = getGroupCombox();
		myCombox2 = getCombox(true);
		MyCombox myCombox3 = getCombox(false);
		checkBoxPanel.add(myCombox);
		checkBoxPanel.add(myCombox2);
		checkBoxPanel.add(myCombox3);

		roundPanel.add(username);
		roundPanel.add(password);
		roundPanel.add(radioPanel);
		roundPanel.add(checkPanel);
		roundPanel.add(checkBoxPanel);
		roundPanel.add(btnPanel);
		roundPanel.setPreferredSize(new Dimension(0	,354));
		
		
		RoundPanel roundPanel2 = new RoundPanel("Radio And CheckBox",true,0.6);
		
		JRadioButton rb3 = new JRadioButton("disable");
		rb3.setEnabled(false);
		JRadioButton rb4 = new JRadioButton("selected disable");
		rb4.setSelected(true);
		rb4.setEnabled(false);
		JPanel tmp1 = new JPanel();
		tmp1.add(rb3);
		tmp1.add(rb4);
		
		JCheckBox ck1 = new JCheckBox("nomal");
		JCheckBox ck2 = new JCheckBox("disable1");
		JCheckBox ck3 = new JCheckBox("disable2");
		ck2.setEnabled(false);
		ck3.setSelected(true);
		ck3.setEnabled(false);
		JPanel tmp2 = new JPanel();
		tmp2.add(ck1);
		tmp2.add(ck2);
		tmp2.add(ck3);
		
		roundPanel2.setLayoutForInner(new VFlowLayout());
		roundPanel2.addCompForInner(tmp1);
		roundPanel2.addCompForInner(tmp2);
		roundPanel2.setPreferredSize(new Dimension(0,220));
		
		this.setLayout(new VFlowLayout(5));
		this.add(roundPanel);
		this.add(roundPanel2);
		
//		testDynamicCombox();
		
		return super.doInit();
	}
	
	public MyCombox getGroupCombox(){
		MyComboxModel model = new MyComboxModel(true);
		model.addItemByGroup("NFC EAST", "Dallas Gayboys", false);
		model.addItemByGroup("NFC EAST", "New York Gaints", false);
		model.addItemByGroup("NFC EAST", "Philadelphia Eagles", false);
		model.addItemByGroup("NFC EAST", "Washington Redskins", false);
		
		model.addItemByGroup("NFC NORTH", "Chicago Bears", false);
		model.addItemByGroup("NFC NORTH", "Detroit Lions", false);
		model.addItemByGroup("NFC NORTH", "Green Bay Packers", false);
		model.addItemByGroup("NFC NORTH", "Minnesota Vikings", false);

		model.addItemByGroup("NFC SOUTH", "Atlanta Falcons", false);
		model.addItemByGroup("NFC SOUTH", "Carolina Panthers", false);
		model.addItemByGroup("NFC SOUTH", "New Orleans Saints", false);
		model.addItemByGroup("NFC SOUTH", "Tampa Bay Buccaneers", false);
		
		model.addItemByGroup("NFC WEST", "Denver Broncos", false);
		model.addItemByGroup("NFC WEST", "Kansas City Chiefs", false);
		model.addItemByGroup("NFC WEST", "Oakland Raiders", false);
		model.addItemByGroup("NFC WEST", "San Diego Chargers", false);
		
		MyCombox myCombox = new MyCombox(model);
		myCombox.setPreferredSize(new Dimension(200,25));
		
		return myCombox;
	}
	
	public MyCombox getCombox(boolean needSearch){
		
		MyComboxModel model = new MyComboxModel(false);
		model.addItem("Option-1", false);
		model.addItem("Option-2", false);
		model.addItem("Option-3", false);
		model.addItem("Option-4", false);
		model.addItem("Option-5", false);
		
		MyCombox myCombox = new MyCombox(model,"-- --");
		myCombox.needSearch = needSearch;
		myCombox.setPreferredSize(new Dimension(100,25));
		
		return myCombox;
	}
	
	//测试  给 comx 添加 条目 删除条目
	public void testDynamicCombox(){
		new Thread(new Runnable() {

			@Override
			public void run() {
				try {
					Thread.sleep(5000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				
				FormsDemo.myCombox2.clear();
				System.out.println("已经清空...");
				
				try {
					Thread.sleep(5000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				
				MyComboxModel model = FormsDemo.myCombox2.model;
				model.addItem("Option-6", false);
				model.addItem("Option-7", false);
				model.addItem("Option-8", false);
				model.addItem("Option-9", false);
				model.addItem("Option-10", false);
				System.out.println("已经重新添加..");
			}
		}).start();
	}
	
	@Override
	public String getPanelKey() {
		return PK;
	}

}
